<?php
class service_search extends Model
{
	function __construct()
	{
		parent::__construct();
	}

	function simpleSearch($tbl, $str)
	{
		
		$cond = "";
		switch($tbl)
		{
			case "company":
				$cond = array(
								"company_name" => $str
								,"company_contact1" => $str
								,"company_contact2" => $str
								,"company_phone1" => $str
								,"company_phone2" => $str
								,"company_address1" => $str
								,"company_suburb" => $str
								,"company_state" => $str
								,"company_postcode" => $str
								,"company_email" => $str
							);
				$this->db->select("company.*, lu.lu_lable as state")
					 	 ->from($tbl)
					 	 ->join("lookup lu", "lu.lu_value=company.company_state and lu.lu_type='states'")
					     ->group_by("company.id")
					     ->where("active" , 1)
					 	 ->or_like($cond);
				break;

			case "job":
				$cond = array(
								"job_subject" => $str
								,"job_description" => $str
							 );
	
							
		$this->db->select("job.*
							,user.firstname
							,user.lastname
							,company.company_name
							
							, lu_pri.lu_lable as job_pri
							, lu_type.lu_lable as job_type
							
							
							, lu_pri.lu_value as job_pri_id
							, lu_type.lu_value as job_type_id"
							
							)
					->from("job")
					->join("company", "job.company_id=company.id")
					->join("user", "user.id=job.job_logged_by")
					
					->join("lookup lu_type", "lu_type.lu_value=job.job_type and lu_type.lu_type='job_type'")
					
					->join("lookup lu_pri", "lu_pri.lu_value=job.job_priority and lu_pri.lu_type='job_pri'")
					->where("job.active" , 1)
					 ->or_like($cond);
				break;
		}
		
		
		

				
		$r = $this->db->get();
		//echo $this->db->last_query();
		return $r->result_array();
	}
	
	function worklogSearch($type, $cond)
	{
		
		
	}
}